package com.zeyuan.rpcclient.netty.debugTool;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.nio.charset.StandardCharsets;

public class Embed {
    public static void main(String[] args) {
        NioSocketChannel nioSocketChannel = new NioSocketChannel();
        ChannelPipeline pipeline = nioSocketChannel.pipeline();
        ChannelInboundHandlerAdapter handler1 = new ChannelInboundHandlerAdapter() {
            @Override
            public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                super.channelRead(ctx, msg);
            }
        };
        ChannelInboundHandlerAdapter handler2 = new ChannelInboundHandlerAdapter() {
            @Override
            public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                super.channelRead(ctx, msg);
            }
        };

        //不用写客户端和服务器端进行handler测试了，用这个
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(handler1, handler2);
        embeddedChannel.writeInbound(ByteBufAllocator.DEFAULT.buffer().writeBytes("hello".getBytes(StandardCharsets.UTF_8))); //模拟入站操作
//        embeddedChannel.writeOutbound()
    }
}
